package com.piano.web.controller.manage;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.piano.common.annotation.Log;
import com.piano.common.enums.BusinessType;
import com.piano.manage.domain.TPayment;
import com.piano.manage.service.ITPaymentService;
import com.piano.framework.web.base.BaseController;
import com.piano.common.page.TableDataInfo;
import com.piano.common.base.AjaxResult;
import com.piano.common.utils.poi.ExcelUtil;

/**
 * 招生提成 信息操作处理
 * 
 * @author pinao
 * @date 2019-02-26
 */
@Controller
@RequestMapping("/manage/tPayment")
public class TPaymentController extends BaseController
{
    private String prefix = "manage/tPayment";
	
	@Autowired
	private ITPaymentService tPaymentService;
	
	@RequiresPermissions("manage:tPayment:view")
	@GetMapping()
	public String tPayment()
	{
	    return prefix + "/tPayment";
	}
	
	/**
	 * 查询招生提成列表
	 */
	@RequiresPermissions("manage:tPayment:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TPayment tPayment)
	{
		startPage();
        List<TPayment> list = tPaymentService.selectTPaymentList(tPayment);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出招生提成列表
	 */
	@RequiresPermissions("manage:tPayment:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TPayment tPayment)
    {
    	List<TPayment> list = tPaymentService.selectTPaymentList(tPayment);
        ExcelUtil<TPayment> util = new ExcelUtil<TPayment>(TPayment.class);
        return util.exportExcel(list, "tPayment");
    }
	
	/**
	 * 新增招生提成
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存招生提成
	 */
	@RequiresPermissions("manage:tPayment:add")
	@Log(title = "招生提成", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TPayment tPayment)
	{		
		return toAjax(tPaymentService.insertTPayment(tPayment));
	}

	/**
	 * 修改招生提成
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		TPayment tPayment = tPaymentService.selectTPaymentById(id);
		mmap.put("tPayment", tPayment);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存招生提成
	 */
	@RequiresPermissions("manage:tPayment:edit")
	@Log(title = "招生提成", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TPayment tPayment)
	{		
		return toAjax(tPaymentService.updateTPayment(tPayment));
	}
	
	/**
	 * 删除招生提成
	 */
	@RequiresPermissions("manage:tPayment:remove")
	@Log(title = "招生提成", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(tPaymentService.deleteTPaymentByIds(ids));
	}
	
}
